﻿@{
	Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<form class="layui-form" action="" style="width:80%;margin:0 auto;">
	<div class="layui-form-item">
		<label class="layui-form-label">供应商编号</label>
		<div class="layui-input-block">
			<input type="hidden" id="Id" name="Id" style="display:none">
			<input type="text" id="RepositoryCode" name="RepositoryCode" lay-verify="required" placeholder="请输入仓库代码" autocomplete="off" style="width:300px" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">供应商名称</label>
		<div class="layui-input-block">
			<input type="text" id="RepositoryName" name="RepositoryName" lay-verify="required" placeholder="请输入仓库名称" autocomplete="off" style="width:300px" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">供应商属性</label>
		<div class="layui-input-block">
			<input type="radio" name="RepositoryAttribute" value="全勤" title="全勤">
			<input type="radio" name="RepositoryAttribute" value="满勤" title="满勤">
			<input type="radio" name="RepositoryAttribute" value="缺勤" title="缺勤">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button type="submit" class="layui-btn" lay-submit lay-filter="add">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			<button type="button" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
		</div>
	</div>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>

<script>

	$(function () {
		getInfo()
	})

	function getInfo() {
		$.ajax({
			url: "/Repository/GetRepositoryInfo",
			data: { id: @ViewBag.id},
			type: "get",
			datatype: "json",
			success: function (res) {
				var id = res.data.id
				console.log(res.data)
				$("#Id").val(res.data.id);
				$("#RepositoryCode").val(res.data.repositoryCode)
				$("#RepositoryName").val(res.data.repositoryName)
				$("[name='RepositoryAttribute'][value=" + res.data.repositoryAttribute + "]").prop("checked", true)

				layui.form.render("radio")
			}
		})
	}

	//关闭弹框
	function closeWorkstation() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}

	layui.use(['form', 'laydate', 'util'], function () {
		var form = layui.form;
		var layer = layui.layer;
		var laydate = layui.laydate;
		var util = layui.util;

		form.on('submit(add)', function (data) {
			var field = data.field;
			console.log(field);
			$.ajax({
				url: '/Supplier/SuppLierUpd',
				type: 'POST',
				data: field,
				dataType: 'json',
				success: function (res) {
					if (res > 0) {
						layer.alert('修改成功', { title: '操作结果' }, function () {
							layer.closeAll();
							closeWorkstation()
						});
					}
					else if(res == -1){
						layer.alert('名称重复');
							return;
					}
					else{
						layer.alert('修改失败：' + res.msg, { title: '操作结果' });
					}
				},
				error: function (err) {
					// 处理添加失败的情况
					layer.alert('修改失败：网络异常，请稍后重试', { title: '操作结果' });
					console.error('修改失败', err);
				}
			});

			return false; // 阻止默认 form 提交
		});
	});
</script>


